<?php
/**
 * Copyright (c) 2008 Pascal MARTIN <contact@pascal-martin.fr>,
 *                    Rémi PERROUD <remi.perroud@gmail.com>
 *      http://code.google.com/p/simpleguestbook/
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * PHP version 5
 *
 * @category Simpleguestbook
 * @package  NoFramework
 * @author   Rémi PERROUD <remi.perroud@gmail.com>
 * @license  http://www.opensource.org/licenses/mit-license.php MIT Licence
 * @link     http://code.google.com/p/simpleguestbook/
 */

/**
 * Gestionnaire de commentaires
 *
 * @category Simpleguestbook
 * @package  NoFramework
 * @author   Rémi PERROUD <remi.perroud@gmail.com>
 * @license  http://www.opensource.org/licenses/mit-license.php MIT Licence
 * @link     http://code.google.com/p/simpleguestbook/
 */
class CommentsManager
{
    private $_dao;

    const COMMENT_MIN_LENGTH = 5;
    const COMMENT_MAX_LENGTH = 100;

    /**
     * Constructeur
     *
     * @param object $dao objet permettant d'accéder aux données des commentaires 
     *
     * @return void
     */
    public function __construct($dao = null)
    {
        if ($dao == null) {
            include_once dirname(__FILE__).'/CommentsDAO.php';
            $this->_dao = new CommentsDAO();
        } else {
            $this->_dao = $dao;
        }
    }

    /**
     * Liste tous les commentaires
     *
     * @return array
     */
    public function listAll()
    {
        return($this->_dao->listAll());
    }

    /**
     * Vérifie si le texte d'un commentaire est valide
     *
     * @param string $text texte à vérifier
     *
     * @return boolean
     */
    public function isTextValid($text)
    {
        return(strlen($text) >= self::COMMENT_MIN_LENGTH  
          &&   strlen($text) <= self::COMMENT_MAX_LENGTH);
    }

}
